/*
 * luaR.h
 */

#ifndef LUAR_H_
#define LUAR_H_

#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>

/*
 * Initializes the LuaR interface. Will attempt to open the file
 * "scripts/preferences.lua" and execute the code inside, establishing the
 * globals to be used by this Lua state.
 */
int luaR_initialize();

/*
 * Creates a new LuaR package. The name of the package is not set until
 * luaR_package_set() is called.
 * Internally, this function creates a new table and pushes it onto the Lua
 * stack.
 */
int luaR_package_create();

/*
 * Adds the given C function to the current Lua package with the given name.
 * Once the package is set, this function can be accessed at any time in a Lua
 * script by calling "packageName.function()".
 * A table must be at the top of the stack, preferably created through
 * luaR_package_create().
 */
int luaR_package_add( const char *name, lua_CFunction f );

/*
 * Sets the current package on the stack with the current name. After this is
 * called, all functions bound to this package can be accessed at any time in a
 * Lua script by calling "packageName.function()"
 * A table must be at the top of the stack, preferably created through
 * luaR_package_create()
 */
int luaR_package_set( const char *name );

/*
 * Registers pkg_name.fn_name as a Lua callback with id fn_id.
 * This function should only be called by ROWGAGE functions!
 */
int luaR_add_callback( const char *pkg_name, const char *fn_name, int fn_id );

/*
 * Attempts to load the given filename as a Lua script and if successful will
 * run the script.
 */
int luaR_load_file( const char *file );

/*
 * Closes the Lua state.
 */
int luaR_close();

/*
 * Attempts to call the given Lua function.
 */
int luaR_fcall( const char *f );

/*
 * Returns the value of t[k] for the current Lua state as a string, first
 * evaluating the value of k to determine the key to use.
 * TODO: better name
 */
int luaR_getconstanti( const char *t, const char *k );

/*
 * Returns the value of t[k] for the current Lua state as a string.
 */
const char * luaR_getconstants( const char *t, const char *k );

#endif
